const changePointPassportBGColor = (sx, sy, canvas, mark, maxPx, sensitive) => {
  sx = Math.ceil(sx);
  sy = Math.ceil(sy);
  //内部方法
  function getColor(x, y, imgData) {
    let i = bgIndex(x, y);
    return [
      imgData.data[i],
      imgData.data[i + 1],
      imgData.data[i + 2],
      imgData.data[i + 3],
    ];
  }
  function bgIndex(x, y) {
    return (y * canvas.width + x) * 4;
  }
  return new Promise((resolve) => {
    //1.获取点击坐标 maxPx 范围内的所有像素点，for循环，进行判断改色
    const colorRgba = {
      red: [255, 0, 0, 255],
      white: [255, 255, 255, 255],
      blue: [0, 0, 255, 255],
    };
    let targetBgArr = colorRgba[mark];
    let blockSX = Math.floor(sx - maxPx / 2);
    let blockSY = Math.floor(sy - maxPx / 2);
    let blockEX = Math.floor(sx + maxPx / 2);
    let blockEY = Math.floor(sy + maxPx / 2);
    blockSX = blockSX < 0 ? 0 : blockSX;
    blockSY = blockSY < 0 ? 0 : blockSY;
    blockEX = blockEX > canvas.width ? canvas.width : blockEX;
    blockEY = blockEY > canvas.height ? canvas.height : blockEY;
    const ctx = canvas.getContext("2d");
    let imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
    let preColor = getColor(sx, sy, imageData); //点击点的颜色
    let worker;
    let wcount = blockEY - blockSY;
    for (let yl = blockSY; yl <= blockEY; yl++) {
      worker = new Worker("./worker.js");
      worker.postMessage(
        JSON.stringify({
          sx: blockSX,
          ex: blockEX,
          y: yl,
          preColor,
          targetBgArr,
          sensitive,
          imageData,
          ctx
        })
      );
      worker.onmessage =  (e) => {
        if(wcount == 0){
          resolve()
        }else{
          wcount --
        }
      };
    }
  });

  // ctx.putImageData(imagedata, 0, 0);
  // return true;
};
